package com.guyu.common.core.enums;

import com.guyu.common.core.enums.able.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.hutool.core.data.IdcardUtil;
import org.dromara.hutool.core.text.StrUtil;

import java.util.Objects;

/**
 * <p> 性别 </p>
 *
 * @author tanyunpeng
 * @date 2023/6/12
 */
@Getter
@AllArgsConstructor
public enum UserGenderTypeEnum implements IEnum<UserGenderTypeEnum> {
    UNKNOWN(0, "未知"),
    MAN(1, "男"),
    WOMAN(2, "女"),
    ;

    private Integer code;
    private String desc;

    /**
     * 获取微信性别
     */
    public static UserGenderTypeEnum parseWx(String gender) {
        if (Objects.equals(UserGenderTypeEnum.MAN.code.toString(), gender)) {
            return MAN;
        } else if (Objects.equals(UserGenderTypeEnum.WOMAN.code.toString(), gender)) {
            return WOMAN;
        }
        return UNKNOWN;
    }

    /**
     * 通过身份证解析性别
     */
    public static UserGenderTypeEnum parseIdCard(String idCard) {
        if (StrUtil.isEmpty(idCard)) {
            return UNKNOWN;
        }
        int gender = IdcardUtil.getGender(idCard);
        if (Objects.equals(1, gender)) {
            return MAN;
        } else if (Objects.equals(0, gender)) {
            return WOMAN;
        }
        return UNKNOWN;
    }

    @Override
    public UserGenderTypeEnum getDefault() {
        return UNKNOWN;
    }


}
